var app = getApp()
var adds = {};
var list = [];

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgalist: ['http://qiniudns.zaishengwang.com/erweima-123.jpeg'],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    currentSwiper: 0,
    buthidden: false,
    userId: "",
    fbType: 1,
    fbTypeText:"供应",
    contacts: "",
    telephone: "",
    textareaData: "",
    images_arr: [],
    categoryText: "请选择",
    text: "",
    areaStatus: false,
    categoryStatus: false,
    areaText: "请选择",
    bId:""

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
   
    var that = this;
    that.setData({
      userId: app.globalData.userId,
      bId: options.bId,
      fbType: options.type
    });
    if (that.data.fbType == 1){
      that.setData({ fbTypeText:"供应"});
    }
    if (that.data.fbType == 2) {
      that.setData({ fbTypeText: "求购" });
    }
    
      that.onOrderInfo();  
  },

  swiperChange: function (e) {
    var that = this ;
    that.setData({
      currentSwiper: e.detail.current
    })
  },

onOrderInfo:function(){
  var that = this;
  wx.request({
    method: "POST",
    url: 'https://www.zaishengwang.com/wx/toSypplyById.do',
    dataType: 'json',
    header: {
      'content-type': 'application/x-www-form-urlencoded',
    },
    data: {
      bId:  that.data.bId
    },
    success: function (res) {
      var supplydemandVo =  res.data.supplydemandVo;
      var imgUrl = [];
      if (supplydemandVo.supplydemandimgVos.length>0){
      for (var i = 0; i < supplydemandVo.supplydemandimgVos.length;i++){
        imgUrl.push(supplydemandVo.supplydemandimgVos[i].img);
        }
      }
      that.setData({
        categoryStatus:true,
        areaStatus: false,
        fbType: supplydemandVo.type,
        contacts: supplydemandVo.contacts,
        telephone: supplydemandVo.telephone,
        //tel: supplydemandVo.telephone.replace(/^(\d{3})\d{4}(\d+)/, "$1****$2"),
        textareaData: supplydemandVo.content,
        images_arr: imgUrl,
        categoryText: supplydemandVo.name,
        categoryId: supplydemandVo.categoryId,
        areaText: supplydemandVo.province + " " + supplydemandVo.city,
        createTime: supplydemandVo.createTime.substring(0, 16)
      });

    },
    fail: function (error) {
      console.log(error);
    }

  })
},

  phonecallevent: function (e) {
    var that = this;
    var tel = e.currentTarget.dataset.tel;
    wx.makePhoneCall({
      phoneNumber: tel
    })

  },

  goHome:function(){
    wx.reLaunch({
      url: '../home/home',
    })
  },

  previewImage: function (e) {
    var that = this;
    wx.previewImage({
      current: that.data.imgalist, // 当前显示图片的http链接   
      urls: that.data.imgalist // 需要预览的图片http链接列表  
    })

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    var that = this;
    return {
      title: '供求详情',
      path: 'pages/supply/supply_detail?bId=' + that.data.bId,
      success: function (res) {
        // 转发成功
        console.log("转发成功:" + JSON.stringify(e));
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(e));
      }
    }
  }
})